package com.example.springsouress.com.config;

import com.example.springsouress.com.bean.HelloCat;
import com.example.springsouress.com.bean.JackDog;
import com.example.springsouress.com.bean.Tomcat;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * -- Created by IntelliJ IDEA.
 * -- REMARK:
 * -- User: tanwei
 * -- Date: 2020/12/10
 * -- Time: 10:30 上午
 * --
 */


/***
 *  这是一个配置类 --beans.xml
 *
 *  proxyBeanMethods: 代理bean方法
 *
 *  为了spring快速加载
 *  Lite Mode   每次直接调用方法获取这个组件
 *  Full Mode 调用方法获取组件的时候、会先判断容器中有没有这个组件，如果有就获取
 *
 *
 * proxyBeanMethods = true: Tomcat的jackD和容器中的jackDog一样
 * proxyBeanMethods = false: Tomcat的jackD和容器中的jackDog 不一样
 *
 *
 */
@Configuration(proxyBeanMethods = true) //默认为true
public class ICodingConfig {

    @Bean
    public Tomcat tomcat(){
        Tomcat tomcat = new Tomcat();

        //@Configuration(proxyBeanMethods = false) 不能这么写
        //配置类中@Bean的所有组件没有依赖关系。  @Configuration(proxyBeanMethods = false)
        tomcat.setJackDog(jackDog());
        return tomcat;
    }
    @Bean
    public JackDog jackDog(){
        JackDog jackDog = new JackDog();
        System.out.printf("容器中的jackDog："+jackDog);
        return jackDog;
    }

    @ConditionalOnMissingBean(Tomcat.class)
    @Bean
    public HelloCat  helloCat(){
        return  new HelloCat();
    }

}
